/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.minierp.dao.BbsArticleDao;
import com.minierp.dao.BbsColumnDao;
import com.minierp.helper.EncCommonHelper;
import com.minierp.model.BbsColumn;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class BbsColumnMACtr extends MultiActionController {
	private BbsColumnDao bbsColumnDao;
	private BbsArticleDao bbsArticleDao;
	private String mainView;
	private String listView;

	public ModelAndView handleMain(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.mainView);
		String defaultId = request.getParameter("default_id");
		if (defaultId != null && !defaultId.equals("")) {
			mv.addObject("defaultId", defaultId);
		}

		String defaultUrl = request.getParameter("default_url");
		if (defaultUrl != null && !defaultUrl.equals("")) {
			mv.addObject("defaultUrl", defaultUrl);
		}

		return mv;
	}

	public ModelAndView handleDelete(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView("redirect:/bbs/BbsColumnList.ihtm");
		String id = request.getParameter("id");
		if (this.bbsArticleDao.getCount(Long.parseLong(id)) > 0) {
			EncCommonHelper.setAlertMessage(request, "该信息栏目下面有帖子，不允许删除！");
		} else {
			this.bbsColumnDao.delete(Long.parseLong(id));
			EncCommonHelper.setAlertMessage(request, "删除成功");
		}

		return mv;
	}

	public ModelAndView handleList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listView);
		List list = this.bbsColumnDao.getList();
		String defaultUrl = request.getParameter("default_url");
		if (defaultUrl != null && !defaultUrl.equals("")) {
			mv.addObject("defaultUrl", defaultUrl);
		}

		String defaultId = request.getParameter("default_id");
		if (defaultId != null && !defaultId.equals("")) {
			mv.addObject("defaultId", defaultId);
		} else if (list.size() > 0) {
			BbsColumn c = (BbsColumn) list.get(0);
			mv.addObject("defaultId", String.valueOf(c.getId()));
		}

		mv.addObject("list", this.bbsColumnDao.getList());
		return mv;
	}

	public BbsColumnDao getBbsColumnDao() {
		return this.bbsColumnDao;
	}

	public void setBbsColumnDao(BbsColumnDao bbsColumnDao) {
		this.bbsColumnDao = bbsColumnDao;
	}

	public String getListView() {
		return this.listView;
	}

	public void setListView(String listView) {
		this.listView = listView;
	}

	public String getMainView() {
		return this.mainView;
	}

	public void setMainView(String mainView) {
		this.mainView = mainView;
	}

	public BbsArticleDao getBbsArticleDao() {
		return this.bbsArticleDao;
	}

	public void setBbsArticleDao(BbsArticleDao bbsArticleDao) {
		this.bbsArticleDao = bbsArticleDao;
	}
}